<template>
  <div class='login-container'>
    <el-form class='login-item' size="large" ref="formlogin" :model="formlogin" label-width="50px" :rules="formrules">
      <el-form-item label="账号" prop="account">
        <el-input v-model="formlogin.account" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formlogin.password" show-password placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-button round type="primary" class="btn-block" v-on:click="onlogin">登录游戏</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      vdata: this.gdata.data,
      formlogin: {
        account: 'ffffff',
        password: '111111'
      },
      formrules: {
        account: [{ required: true, message: '账号不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
      }
    }
  },
  components: {
    // websocket: websocket
  },
  methods: {
    onlogin: function (event) {
      var req = this.wsreq('C2L_LOGIN_USERLOGIN')
      req.Account = this.formlogin.account
      req.Password = this.formlogin.password
      this.wssend(req)
    },
    onkeyevent: function (key) {
      // 回车
      if (key === 13) {
        this.onlogin()
      }
    },
    G2C: function (pid, rsp, success, result) {
      switch (pid) {
        case 'L2C_LOGIN_USERLOGIN':
          var req = this.wsreq('C2G_LOGIN_PLAYERLOGIN')
          req.Uuid = rsp.Uuid
          req.Code = rsp.Code
          this.wssend(req)
          break
        case 'G2C_LOGIN_PLAYERLOGIN':
          if (rsp.Shuttle === 'create') {
            this.jxpage('create')
          } else {
            var reqinfo = this.wsreq('C2G_INFO_GETALL')
            this.wssend(reqinfo)
            this.jxpage('game')
          }
          break
        default:
          break
      }
    }
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  align-items: center;
  justify-content: center;
}
.login-item {
  width: 50vw;
}
</style>
